package com.study.listener;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * HttpSessionListener 用于监控 session 的创建，销毁等
 * ServletRequestListener 用于监控 servlet 上下文 request
 * ServletRequestAttributeListener 用于监控 request 中的 attribute 的操作
 * <p>
 * 自定义 Listener：基于注解配置
 *
 * @author Administrator
 */
@Slf4j
@WebListener
public class TestListenerAnnotation implements HttpSessionListener, ServletRequestListener, ServletRequestAttributeListener {
    @Override
    public void sessionCreated(HttpSessionEvent arg) {
        log.info("TestListenerAnnotation sessionCreated().......");
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent arg) {
        log.info("TestListenerAnnotation sessionDestroyed().......");
    }

    @Override
    public void requestInitialized(ServletRequestEvent arg) {
        log.info("TestListenerAnnotation requestInitialized()......");
    }

    @Override
    public void requestDestroyed(ServletRequestEvent arg) {
        log.info("TestListenerAnnotation requestDestroyed()......");
    }

    @Override
    public void attributeAdded(ServletRequestAttributeEvent arg) {
        log.info("TestListenerAnnotation attributeAdded()......");
    }

    @Override
    public void attributeRemoved(ServletRequestAttributeEvent arg) {
        log.info("TestListenerAnnotation attributeRemoved()......");
    }

    @Override
    public void attributeReplaced(ServletRequestAttributeEvent arg) {
        log.info("TestListenerAnnotation attributeReplaced()......");
    }
}
